<style>
    #esb-service-add {
        padding: 20px 25px 25px 0;
        margin: 0 0 2px 3px !important;
    }

</style>
<div class="layui-fluid" id="service-info-apply">
    <form class="layui-form" method="post" onsubmit="return false">
        <!--<input hidden name="serviceId" th:value="${serviceInfo.serviceId}">-->
        <input hidden name="role" value="2">
        <input hidden name="applyStatus" value="1">
        <div class="layui-form-item">
            <label class="layui-form-label">调用频率：</label>
            <div class="layui-input-block">
                <input type="radio" name="frequency" value="10000" title="1万次/天" checked>
                <input type="radio" name="frequency" value="50000" title="5万次/天">
                <input type="radio" name="frequency" value="100000" title="10万次/天">
            </div>
        </div>
        <div class="layui-row layui-col-space10 layui-form-item">
            <label class="layui-form-label">调用IP：</label>
            <div class="layui-input-block">
                <input name="ips" lay-verify="required|ips"
                       placeholder="例如：123.23.22.2,12.36.23.3" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item febs-hide">
            <button class="layui-btn" lay-submit="" lay-filter="service-info-apply-submit" id="submit"></button>
            <button type="reset" class="layui-btn" id="reset"></button>
        </div>

    </form>
</div>

<script>
    //  https://www.open-open.com/code/view/1430625516632
    layui.use(['febs', 'form'], function () {
        var $ = layui.$,
            febs = layui.febs,
            form = layui.form,
            pop_data = POPUP_DATA,
            freq = pop_data.userService.userServiceFrequency,
            formRepeat = false;// 表单重复提交 出此下策
        console.log(" pop data");
        console.log(pop_data);

        if (freq > 50000) {
            $("input:radio[name=frequency][value='100000']").attr("checked",true);
        }else if (freq == 50000) {
            $("input:radio[name=frequency][value='50000']").attr("checked",true);
        }else
            $("input:radio[name=frequency][value='10000']").attr("checked",true);

        $('input[name=ips]').val(pop_data.userService.userServiceIps);
        form.render();

        form.verify({
            ips: function (ip) {
                var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
                var d = ip.split(',');
                for (var i = 0; i < d.length; i++) {
                    if (reg.test(d[i]) == false) return "Ip格式不正确";
                }
            }
        });

        /* 监听提交 */
        form.on('submit(service-info-apply-submit)', function (data) {

            data.field.userServiceId = pop_data.userService.userServiceId;

            if (formRepeat) {
                formRepeat = false;
                return false;
            } else {
                formRepeat = true;
                febs.post(ctx + 'userService/update', data.field, function () {
                    layer.closeAll();
                    febs.alert.success('添加成功');
                    $('#mine-service-apply-form').find('#applied-query').click();
                });
            }
            return false;
        });

    });
</script>